package com.neteast.androidclient.newscenter.activity;

import com.neteast.androidclient.newscenter.R;
import com.neteast.androidclient.newscenter.util.ConfigUtil;
import com.neteast.androidclient.newscenter.util.LoginUtil;
import android.app.Activity;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;

public class ConfigActivity extends Activity implements OnCheckedChangeListener{
	private CheckBox autoClose;
	private CheckBox broadcastNotify;
	private CheckBox deleteConfirm;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.newscenter_config);
		initView();
	}
	@Override
	protected void onResume() {
		super.onResume();
		autoClose.setChecked(ConfigUtil.getAutoClose(this,LoginUtil.getUserId(this)));
		broadcastNotify.setChecked(ConfigUtil.getCloseBroadcastNotify(this,LoginUtil.getUserId(this)));
		deleteConfirm.setChecked(ConfigUtil.getDeleteConfirm(this,LoginUtil.getUserId(this)));
	}
	
	private void initView() {
		autoClose = (CheckBox) this.findViewById(R.id.config_auto_close);
		broadcastNotify = (CheckBox) this.findViewById(R.id.config_broadcast_notify);
		deleteConfirm = (CheckBox) this.findViewById(R.id.config_delete_confirm);
		
		autoClose.setOnCheckedChangeListener(this);
		broadcastNotify.setOnCheckedChangeListener(this);
		deleteConfirm.setOnCheckedChangeListener(this);
	}

	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		switch (buttonView.getId()) {
		case R.id.config_auto_close:
			ConfigUtil.setAutoClose(this, LoginUtil.getUserId(this),isChecked);
			break;
		case R.id.config_broadcast_notify:
			ConfigUtil.setCloseBroadcastNotify(this, LoginUtil.getUserId(this),isChecked);
			break;
		case R.id.config_delete_confirm:
			ConfigUtil.setDeleteConfirm(this, LoginUtil.getUserId(this),isChecked);
			break;
		}
	}
}
